<!DOCTYPE html>
<html lang="zh">
<head>
    <title>数据库备份中心</title>
    <{include file="bs_db_backup/public/header"}>
    <{include file="bs_db_backup/public/data_tables_css"}>

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<!-- Site wrapper -->
<div class="wrapper">
    <!-- Navbar -->
    <{include file="bs_db_backup/public/navbar"}>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <!--左侧菜单-->
    <{include file="bs_db_backup/public/sidebar"}>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">


                <div class="card">
                    <div class="card-header show-doing" style="display: none">
                        <div class="alert alert-danger">
                            <p>正在进行备份，请勿耐心等待,已用时间： <span class="wait">0</span> 秒</p>
                        </div>
                    </div>

                    <div class="card-body">
                        <span onclick="add_backup()" class="btn btn-success">新增备份</span>
                        <table id="my_table" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>大小</th>
                                <th>时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <{if !empty($data)}>
                            <{foreach $data as $item}>
                            <tr>
                               <td><{$item.name}></td>
                               <td><{$item.size}></td>
                               <td><{$item.add_time}></td>
                               <td>
                                   <a href="<{:url('download_backup',['fname'=>$item.name])}>" title="下载" class="btn btn-sm btn-default "><i class="fas fa-download"></i></a>
                                   <span onclick="del('<{$item.name}>')" title="删除" class="btn  btn-sm btn-danger bs-left-10 "><i class="fas fa-trash"></i></span>
                               </td>

                            </tr>
                            <{/foreach}>
                            <{/if}>



                            </tbody>
                            <tfoot>


                            </tfoot>
                        </table>
                    </div>

                </div>
            </div>

        </section>
    </div>


</div>
<!-- ./wrapper -->

<{include file="bs_db_backup/public/footer"}>
<!-- DataTables  & Plugins -->
<{include file="bs_db_backup/public/data_tables"}>
<script>
    $(function () {
        $("#my_table").DataTable({
            "ordering": false,//禁用排序
            "responsive": true,
            "lengthChange": false,
            "autoWidth": false,
            //"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
            // "pageLength": 10,         //初始化显示几条数据
            //serverSide: true, // use local process instead of server
            // bFilter: true, // show top right search input box.
            bPaginate: true,//是否开启分页
            iDisplayLength: 10, //默认显示的记录数
            bInfo: false,//是否显示页脚信息，DataTables插件左下角显示记录数
        }).buttons().container().appendTo('#my_table_wrapper .col-md-6:eq(0)');

    });

    function del(fname) {
        layer.confirm('确定要删除备份"'+fname+'"吗？',{title:0},function () {
            sendData("<{:url('del_backup')}>",{fname:fname},function (res) {
                if (res.code==0){
                    location.reload()
                }
            })
        })
    }

    function add_backup() {
        layer.confirm('确定要新增备份吗,备份时间由数据库大小决定，请不要关闭当前页面？',{title:0},function () {
            $(".show-doing").show();

            var t =setInterval(function () {
                $(".wait").text(Number($(".wait").text())+1) ;
            },1000)

            sendData("<{:url('add_backup')}>",{},function (res) {
                $(".show-doing").hide();
                clearInterval(t)
                if (res.code==0){
                    location.reload()
                }
            })
        })
    }
</script>
</body>
</html>
